<?php
require_once ('../lib/config.php');
require_once ('../lib/facebook.php');
require_once ('../lib/friends.php');
require_once ('../lib/friend.php');
require_once ('../lib/test.php');
require_once ('../../simpletest/autorun.php');
require_once ('../lib/init.php');

class TestTemplate extends UnitTestCase {

    function setUp(){
        global $login_button;
        try{
            $me = getOneself();
        }catch(FacebookApiException $e){
            print($login_button);
            exit();
        }
    }
    
    //refer to http://www.simpletest.org/en/unit_test_documentation.html
    function testGetAllDataFromFQL(){ 
        $data = getAllDataFromFQL();
        $this->assertNull($data);
    }

    function messageCheck($data){
        $result = getResultSet('threadQuery', $data);
        
        if(empty($result) || !is_array($result)){
            return false;
        }
        
        $result = getResultSet('messageQuery', $data);
        if(empty($result) || !is_array($result)){
            return false;
        }
        
        return true;
    }
    
    function postCheck($data){
        $result = getResultSet('friendsPostQuery', $data);
        
        if(empty($result) || !is_array($result)){
            return false;
        }
        return true;
    }

    function commentCheck($data){
        $result = true;
        if(!(self::friendCommentCheck($data) && self::myNoteCommentCheck($data) && self::myStatusCommentCheck && self::myLinkCommentCheck)){
            $result = false;
        }
        return $result;
    }
    
    function friendCommentCheck($data){
        $result = getResultSet('friendsCommentQuery', $data);
        
        if(empty($result) || !is_array($result)){
            return false;
        }

        return true;
    }

    function myNoteCommentCheck($data){
        
        $result = getResultSet('myCommentNoteQuery', $data);
        
        if(empty($result) || !is_array($result)){
            return false;
        }

        return true;
    }    
    
    function myStatusCommentCheck($data){
        
        $result = getResultSet('myCommentStatusQuery', $data);
        
        if(empty($result) || !is_array($result)){
            return false;
        }

        return true;
    }

    function myLinkCommentCheck($data){
        
        $result = getResultSet('myCommentLinkQuery', $data);
        
        if(empty($result) || !is_array($result)){
            return false;
        }
        return true;
    }    
    
    function likeCheck($data){
        $result = getResultSet('friendsLikesQuery', $data);
        
        if(empty($result) || !is_array($result)){
            return false;
        }
        
        $result = getResultSet('myLikeNoteQuery', $data);
        
        if(empty($result) || !is_array($result)){
            return false;
        }
        
        $result = getResultSet('myLikeStatusQuery', $data);
        
        if(empty($result) || !is_array($result)){
            return false;
        }
        
        $result = getResultSet('myLikeLinkQuery', $data);
        
        if(empty($result) || !is_array($result)){
            return false;
        }
        return true;
    }
    
    function testMessage(){
        
        $data = getAllDataFromFQL(MESSAGE_FLAG);
var_export($data);        
        $this->assertTrue(self::messageCheck($data));
        $this->assertFalse(self::postCheck($data));
        $this->assertFalse(self::commentCheck($data));
        $this->assertFalse(self::likeCheck($data));
    }
    
    function testPost(){
        $data = getAllDataFromFQL(POST_FLAG);
        
        $this->assertFalse(self::messageCheck($data));
        $this->assertTrue(self::postCheck($data));
        $this->assertFalse(self::commentCheck($data));
        $this->assertFalse(self::likeCheck($data));
    }
    
    function testFriendComment(){
        $data = getAllDataFromFQL(FRIEND_COMMENT_FLAG);
        $this->assertFalse(self::messageCheck($data));
        $this->assertFalse(self::postCheck($data));
        $this->assertTrue(self::friendCommentCheck($data));
        $this->assertFalse(self::myNoteCommentCheck($data));
        $this->assertFalse(self::myLinkCommentCheck($data));
        $this->assertFalse(self::myStatusCommentCheck($data));
        $this->assertFalse(self::likeCheck($data));
    }
    
    function testMyNoteComment(){
        $data = getAllDataFromFQL(MY_NOTE_COMMENT_FLAG);
        $this->assertFalse(self::messageCheck($data));
        $this->assertFalse(self::postCheck($data));
        $this->assertFalse(self::friendCommentCheck($data));
        $this->assertTrue(self::myNoteCommentCheck($data));
        $this->assertFalse(self::myLinkCommentCheck($data));
        $this->assertFalse(self::myStatusCommentCheck($data));
        $this->assertFalse(self::likeCheck($data));
    }
    function testMyLinkComment(){
        $data = getAllDataFromFQL(MY_LINK_COMMENT_FLAG);
        $this->assertFalse(self::messageCheck($data));
        $this->assertFalse(self::postCheck($data));
        $this->assertFalse(self::friendCommentCheck($data));
        $this->assertFalse(self::myNoteCommentCheck($data));
        $this->assertTrue(self::myLinkCommentCheck($data));
        $this->assertFalse(self::myStatusCommentCheck($data));
        $this->assertFalse(self::likeCheck($data));
    }
    function testMyStatusComment(){
        $data = getAllDataFromFQL(MY_STATUS_COMMENT_FLAG);
        $this->assertFalse(self::messageCheck($data));
        $this->assertFalse(self::postCheck($data));
        $this->assertFalse(self::friendCommentCheck($data));
        $this->assertFalse(self::myNoteCommentCheck($data));
        $this->assertFalse(self::myLinkCommentCheck($data));
        $this->assertTrue(self::myStatusCommentCheck($data));
        $this->assertFalse(self::likeCheck($data));
    }
    
    function testLike(){
        $data = getAllDataFromFQL(LIKE_FLAG);
        $this->assertFalse(self::messageCheck($data));
        $this->assertFalse(self::postCheck($data));
        $this->assertFalse(self::commentCheck($data));
        $this->assertTrue(self::likeCheck($data));
    }
    
    function testMessageAndPost(){
        $mode = MESSAGE_FLAG + POST_FLAG;
        $data = getAllDataFromFQL($mode);
        $this->assertTrue(self::messageCheck($data));
        $this->assertTrue(self::postCheck($data));
        $this->assertFalse(self::commentCheck($data));
        $this->assertFalse(self::likeCheck($data));
    }
    
    function testPostAndComment(){
        $mode = POST_FLAG + COMMENT_FLAG;
        $data = getAllDataFromFQL($mode);
        $this->assertFalse(self::messageCheck($data));
        $this->assertTrue(self::postCheck($data));
        $this->assertTrue(self::commentCheck($data));
        $this->assertFalse(self::likeCheck($data));
    }
    
    function testAll(){
        $mode = MESSAGE_FLAG + POST_FLAG + COMMENT_FLAG + LIKE_FLAG;
        $data = getAllDataFromFQL($mode);
        $this->assertTrue(self::messageCheck($data));
        $this->assertTrue(self::postCheck($data));
        $this->assertTrue(self::commentCheck($data));
        $this->assertTrue(self::likeCheck($data));
    }
    
}
?>
